-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support translate BackendTrafficPolicy CRD #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support translate BackendTrafficPolicy CRD #92
Conversation
conformance test reportapiVersion: gateway.networking.k8s.io/v1
date: "2025-04-16T08:44:19Z"
gatewayAPIChannel: standard
gatewayAPIVersion: v1.2.0
implementation:
contact: null
organization: API7
project: api7-ingress-controller
url: https://github.com/api7/api7-ingress-controller.git
version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
failedTests:
- HTTPRoutePathMatchOrder
- HTTPRouteSimpleSameNamespace
result: failure
skippedTests:
- GatewayInvalidTLSConfiguration
- GatewaySecretInvalidReferenceGrant
- GatewaySecretMissingReferenceGrant
- GatewaySecretReferenceGrantAllInNamespace
- GatewaySecretReferenceGrantSpecific
- HTTPRouteExactPathMatching
- HTTPRouteHTTPSListener
- HTTPRouteHeaderMatching
- HTTPRouteHostnameIntersection
- HTTPRouteInvalidBackendRefUnknownKind
- HTTPRouteInvalidCrossNamespaceBackendRef
- HTTPRouteInvalidCrossNamespaceParentRef
- HTTPRouteInvalidNonExistentBackendRef
- HTTPRouteInvalidParentRefNotMatchingSectionName
- HTTPRouteInvalidReferenceGrant
- HTTPRouteListenerHostnameMatching
- HTTPRouteMatching
- HTTPRouteMatchingAcrossRoutes
- HTTPRoutePartiallyInvalidViaInvalidReferenceGrant
- HTTPRouteReferenceGrant
- HTTPRouteRequestHeaderModifier
- HTTPRouteWeight
statistics:
Failed: 2
Passed: 9
Skipped: 22
name: GATEWAY-HTTP
summary: Core tests failed with 2 test failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for translating the new BackendTrafficPolicy CRD within the ingress controller by extending the translation context, translator, and controller logic while also updating the CRD definitions and associated types.
- Changes to the TranslateContext to encapsulate context and include BackendTrafficPolicies and StatusUpdaters.
- Enhancements in translator and controller logic to attach BackendTrafficPolicy configurations and update indexers.
- Updates to CRD YAML defaults and deepcopy functions to support the new CRD.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/provider/provider.go | Updated TranslateContext and constructor to accept a context and initialize maps. |
| internal/provider/adc/translator/policies.go | Added functions to attach BackendTrafficPolicy to upstreams. |
| internal/provider/adc/translator/ingress.go & httproute.go | Updated to invoke attachBackendTrafficPolicyToUpstream in translation routines. |
| internal/controller/* | Propagated context usage in status, policies, and ingress reconciler logic. |
| internal/controller/indexer/indexer.go | Added indexer support for BackendTrafficPolicy target references. |
| CRD YAML and api files | Updated CRD defaults, deep copy functions, and type definitions for Back...... |
Comments suppressed due to low confidence (1)
internal/provider/adc/translator/policies.go:31
- Consider using a lower log level (e.g. Info or Debug) here since attaching a BackendTrafficPolicy appears to be a normal operation; using an error log might mislead monitoring systems.
log.Errorw("attach backend traffic policy to upstream", zap.String("policy", policy.Name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
internal/provider/adc/translator/ingress.go:112
- Calling attachBackendTrafficPolicyToUpstream with a nil policy results in a no-op. Consider adding a conditional to only invoke this function when a valid policy exists, or document the rationale for this call.
t.attachBackendTrafficPolicyToUpstream(nil, upstream)
internal/provider/adc/translator/httproute.go:293
- Using a nil policy in attachBackendTrafficPolicyToUpstream may be redundant. Review whether this call is necessary or if it should be conditioned on a non-nil policy.
t.attachBackendTrafficPolicyToUpstream(nil, upstream)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api7-ingress-controller/config/crd/bases/gateway.apisix.io_backendtrafficpolicies.yaml
Lines 161 to 165 in c9fa9f4
| x-kubernetes-list-map-keys: | |
| - group | |
| - kind | |
| - name | |
| x-kubernetes-list-type: map |
这里会以这些字段为 key,也就不能出现同样的 group kind name 组合,符合期望吗?
| SecretIndexRef = "secretRefs" | ||
| IngressClassRef = "ingressClassRef" | ||
| ConsumerGatewayRef = "consumerGatewayRef" | ||
| PolicyTargetRefs = "targetRefs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be renamed to BackendTrafficPolicyTargetRefs or BTPolicyTargetRefs to distinguish it from HTTPRoutePolicyTargetRefs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to distinguish? This index key is for resources with targetrefs.
| backendTrafficPolicyList := &v1alpha1.BackendTrafficPolicyList{} | ||
| if err := c.List(tctx, backendTrafficPolicyList, | ||
| client.MatchingFields{ | ||
| indexer.PolicyTargetRefs: indexer.GenIndexKeyWithGK("", "Service", service.Namespace, service.Name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is empty string for group ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The group of the service is an empty string.
internal/controller/policies.go
Outdated
| condition := NewPolicyCondition(policy.Generation, true, "Policy has been accepted") | ||
| if sectionName != nil && !portNameExist[string(*sectionName)] { | ||
| condition = NewPolicyCondition(policy.Generation, false, fmt.Sprintf("SectionName %s not found in Service %s/%s", *sectionName, service.Namespace, service.Name)) | ||
| goto record_status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the use of goto be avoided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
| Connect: policy.Spec.Timeout.Connect.Duration.Milliseconds(), | ||
| Read: policy.Spec.Timeout.Read.Duration.Milliseconds(), | ||
| Send: policy.Spec.Timeout.Send.Duration.Milliseconds(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dashboard API, the unit is second. It is millsecond in adc ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Type of change:
What this PR does / why we need it:
Only a portion of the conversion logic has been implemented.
TODO:
Pre-submission checklist: